package com.lxmes.hr.service.impl;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

import com.lxmes.common.exception.ServiceException;
import com.lxmes.common.utils.DateUtils;
import com.lxmes.common.utils.HrGeneraRuleUtils;
import com.lxmes.common.utils.SecurityUtils;
import com.lxmes.common.utils.StringUtils;
import com.lxmes.common.utils.bean.BeanUtils;
import com.lxmes.common.utils.bean.BeanValidators;
import com.lxmes.hr.domain.*;
import com.lxmes.hr.mapper.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.lxmes.hr.service.INcWagesGzhsService;
import org.springframework.transaction.annotation.Transactional;

import javax.validation.Validator;

/**
 * 工资核算Service业务层处理
 *
 * @author lx
 * @date 2023-03-21
 */
@Service
public class NcWagesGzhsServiceImpl implements INcWagesGzhsService
{
    @Autowired
    private NcWagesGzhsMapper ncWagesGzhsMapper;

    @Autowired
    private NcWagesAccountMapper ncWagesAccountMapper;

    @Autowired
    private NcAttendSummaryMapper ncAttendSummaryMapper;

    @Autowired
    private NcPieceworkMoneySummaryMapper ncPieceworkMoneySummaryMapper;

    @Autowired
    private NcGsjsMapper ncGsjsMapper;

    @Autowired
    private NcGsszMapper ncGsszMapper;

    @Autowired
    private NcPersonnelInfoMapper ncPersonnelInfoMapper;

    @Autowired
    protected Validator validator;

    /**
     * 查询工资核算
     *
     * @param id 工资核算主键
     * @return 工资核算
     */
    @Override
    public NcWagesGzhs selectNcWagesGzhsById(Long id)
    {
        return ncWagesGzhsMapper.selectNcWagesGzhsById(id);
    }

    /**
     * 查询工资核算列表
     *
     * @param ncWagesGzhs 工资核算
     * @return 工资核算
     */
    @Override
    public List<NcWagesGzhs> selectNcWagesGzhsList(NcWagesGzhs ncWagesGzhs)
    {
        ncWagesGzhs.setIsDelete("1");
        return ncWagesGzhsMapper.selectNcWagesGzhsList(ncWagesGzhs);
    }

    /**
     * 新增工资核算
     *
     * @param ncWagesGzhs 工资核算
     * @return 结果
     */
    @Override
    public int insertNcWagesGzhs(NcWagesGzhs ncWagesGzhs)
    {
        ncWagesGzhs.setCreateTime(DateUtils.getNowDate());
        return ncWagesGzhsMapper.insertNcWagesGzhs(ncWagesGzhs);
    }

    /**
     * 修改工资核算
     *
     * @param ncWagesGzhs 工资核算
     * @return 结果
     */
    @Override
    public int updateNcWagesGzhs(NcWagesGzhs ncWagesGzhs)
    {
        ncWagesGzhs.setUpdateTime(DateUtils.getNowDate());
        return ncWagesGzhsMapper.updateNcWagesGzhs(ncWagesGzhs);
    }

    /**
     * 批量删除工资核算
     *
     * @param ids 需要删除的工资核算主键
     * @return 结果
     */
    @Override
    public int deleteNcWagesGzhsByIds(Long[] ids)
    {
        for(long id : ids){
            NcWagesGzhs ncWagesGzhs = ncWagesGzhsMapper.selectNcWagesGzhsById(id);
            ncWagesGzhs.setIsDelete("0");
            ncWagesGzhsMapper.updateNcWagesGzhs(ncWagesGzhs);
        }

        return 1;
    }

    /**
     * 删除工资核算信息
     *
     * @param id 工资核算主键
     * @return 结果
     */
    @Override
    public int deleteNcWagesGzhsById(Long id)
    {
        return ncWagesGzhsMapper.deleteNcWagesGzhsById(id);
    }
    @Override
    public String imporIteminfo(List<NcWagesGzhs> ncWagesGzhsList, boolean updateSupport, String operName) {
        if (StringUtils.isNull(ncWagesGzhsList) || ncWagesGzhsList.size() == 0)
        {
            throw new ServiceException("导入数据不能为空！");
        }
        int successNum = 0;
        int failureNum = 0;
        StringBuilder successMsg = new StringBuilder();
        StringBuilder failureMsg = new StringBuilder();
        for (NcWagesGzhs ncWagesGzhs : ncWagesGzhsList)
        {
            try
            {
                BeanValidators.validateWithException(validator, ncWagesGzhs);

                if(StringUtils.isNull(ncWagesGzhs.getYfBasicWages())|StringUtils.isEmpty(ncWagesGzhs.getYfBasicWages()+"")){
                    ncWagesGzhs.setYfBasicWages(HrGeneraRuleUtils.yfjbgz(ncWagesGzhs.getJbType(),ncWagesGzhs.getAttendCalBase(),ncWagesGzhs.getBaseWages()));
                }

                if(StringUtils.isNull(ncWagesGzhs.getYfGwzrWages())|StringUtils.isEmpty(ncWagesGzhs.getYfGwzrWages()+"")){
                    ncWagesGzhs.setYfGwzrWages(HrGeneraRuleUtils.yfgwgz(ncWagesGzhs.getJbType(),ncWagesGzhs.getZrgwWages(),ncWagesGzhs.getAttendCalBase()));
                }

                if(StringUtils.isNull(ncWagesGzhs.getYfJbWages())|StringUtils.isEmpty(ncWagesGzhs.getYfJbWages()+"")){
                    ncWagesGzhs.setYfJbWages(HrGeneraRuleUtils.workOverTime(ncWagesGzhs.getJbType(),ncWagesGzhs.getDxwTime(),ncWagesGzhs.getBaseWages(),ncWagesGzhs.getZrgwWages(),ncWagesGzhs.getAttendCalBase()));
                }

                if(StringUtils.isNull(ncWagesGzhs.getYfJxWages())|StringUtils.isEmpty(ncWagesGzhs.getYfJxWages()+"")){
                    ncWagesGzhs.setYfJxWages(HrGeneraRuleUtils.yfjxgz(ncWagesGzhs.getJbType(),ncWagesGzhs.getJxWages(),ncWagesGzhs.getAttendCalBase()));
                }

                if(StringUtils.isNull(ncWagesGzhs.getYfJjWages())|StringUtils.isEmpty(ncWagesGzhs.getYfJjWages()+"")){
                    NcPieceworkMoneySummary moneySummary = new NcPieceworkMoneySummary();
                    moneySummary.setJobNo(ncWagesGzhs.getJobNum());
                    moneySummary.setPieceworkDate(ncWagesGzhs.getCurrentYm());
                    List<NcPieceworkMoneySummary> ncPieceworkMoneySummaries = ncPieceworkMoneySummaryMapper.selectNcPieceworkMoneySummaryList(moneySummary);
                    if(ncPieceworkMoneySummaries.size()>0){
                        BigDecimal a = ncPieceworkMoneySummaries.get(0).getPieceworkSummary()==null?new BigDecimal(0) :ncPieceworkMoneySummaries.get(0).getPieceworkSummary();
                        ncWagesGzhs.setYfJjWages(a);
                    }else{
                        ncWagesGzhs.setYfJjWages(new BigDecimal(0));
                    }
                }

                if(StringUtils.isNull(ncWagesGzhs.getYfWagesTotal())|StringUtils.isEmpty(ncWagesGzhs.getYfWagesTotal()+"")){
                    ncWagesGzhs.setYfWagesTotal(yfgzhj(ncWagesGzhs));//应发工资合计
                }

                if(StringUtils.isNull(ncWagesGzhs.getActualWagesTotal())|StringUtils.isEmpty(ncWagesGzhs.getActualWagesTotal()+"")){
                    ncWagesGzhs.setActualWagesTotal(actualWagesTotal(ncWagesGzhs));//实际发工资
                }


                ncWagesGzhs.setCreateBy(operName);
                ncWagesGzhs.setUpdateBy(operName);
                ncWagesGzhs.setDataSource("2");
                this.insertNcWagesGzhs(ncWagesGzhs);
                successNum++;
                successMsg.append("<br/>" + successNum + "数据导入成功");
            }
            catch (Exception e)
            {
                failureNum++;
                String msg = "<br/> 数据导入失败：";
                failureMsg.append(msg + e.getMessage());
            }
        }
        if (failureNum > 0)
        {
            failureMsg.insert(0, "很抱歉，导入失败！共 " + failureNum + " 条数据格式不正确，错误如下：");
            throw new ServiceException(failureMsg.toString());
        }
        else
        {
            successMsg.insert(0, "恭喜您，数据已全部导入成功！共 " + successNum + " 条，数据如下：");
        }
        return successMsg.toString();
    }


    /*核算工资*/
    @Override
    @Transactional
    public int accountWage(String ny,String sjly) {
        NcPersonnelInfo person = new NcPersonnelInfo();
        person.setState("1");
        List<NcPersonnelInfo> personnelInfos = ncPersonnelInfoMapper.selectNcPersonnelInfoList(person);
        List<NcWagesAccount> ncWagesAccounts = ncWagesAccountMapper.selectNcWagesAccountList(null);

        NcWagesGzhs ncWagesGzhs;
        for(NcPersonnelInfo personnelInfo : personnelInfos){
            if("计件".equals(personnelInfo.getShift())){
                ncWagesGzhs = new NcWagesGzhs();
                ncWagesGzhs.setFactoryCode(personnelInfo.getFactoryCode());
                ncWagesGzhs.setFactoryName(personnelInfo.getFactoryName());
                ncWagesGzhs.setWaName(personnelInfo.getPName());
                ncWagesGzhs.setJobNum(personnelInfo.getJobNo());
                ncWagesGzhs.setDepartment(personnelInfo.getDepartment());
                ncWagesGzhs.setDivision(personnelInfo.getBranch());
                ncWagesGzhs.setWaGroup(personnelInfo.getPGroup());
                ncWagesGzhs.setPost(personnelInfo.getJobs());
                ncWagesGzhs.setCurrentYm(ny);
                NcPieceworkMoneySummary moneySummary = new NcPieceworkMoneySummary();
                moneySummary.setJobNo(personnelInfo.getJobNo());
                moneySummary.setPieceworkDate(ny);
                List<NcPieceworkMoneySummary> ncPieceworkMoneySummaries = ncPieceworkMoneySummaryMapper.selectNcPieceworkMoneySummaryList(moneySummary);
                if(ncPieceworkMoneySummaries.size()>0){
                    BigDecimal a = ncPieceworkMoneySummaries.get(0).getPieceworkSummary()==null?new BigDecimal(0) :ncPieceworkMoneySummaries.get(0).getPieceworkSummary();
                    ncWagesGzhs.setYfJjWages(a);
                }else{
                    ncWagesGzhs.setYfJjWages(new BigDecimal(0));
                }
                List<NcWagesAccount> collect = ncWagesAccounts.stream().filter(ncWagesAccount -> ncWagesAccount.getJobNum().equals(personnelInfo.getJobNo())).collect(Collectors.toList());
                if(collect.size()==0){
                    ncWagesGzhs.setInsurance(BigDecimal.valueOf(0));
                    ncWagesGzhs.setZfgjj(BigDecimal.valueOf(0));
                }else{
                    ncWagesGzhs.setInsurance(collect.get(0).getInsurance());
                    ncWagesGzhs.setZfgjj(collect.get(0).getZfgjj());
                }
                ncWagesGzhs.setYfWagesTotal(yfgzhj(ncWagesGzhs));//应发工资合计
                ncWagesGzhs.setGrsds(new BigDecimal(0));//个人所得税
                ncWagesGzhs.setOtherKk(new BigDecimal(0));//其他扣款
                ncWagesGzhs.setActualWagesTotal(actualWagesTotal(ncWagesGzhs));//实际发工资
                BigDecimal sjse = calculateGs(ncWagesGzhs);
                ncWagesGzhs.setDataSource("1");
                ncWagesGzhs.setGrsds(sjse);
                ncWagesGzhs.setActualWagesTotal(ncWagesGzhs.getActualWagesTotal().subtract(ncWagesGzhs.getGrsds()));
                insertNcWagesGzhs(ncWagesGzhs);
            }else{
                ncWagesGzhs = new NcWagesGzhs();
                NcAttendSummary ncAttendSummary = new NcAttendSummary();
                ncAttendSummary.setKqDate(ny);
                if("1".equals(sjly)){
                    ncAttendSummary.setDataSource("rg");
                }else{
                    ncAttendSummary.setDataSource("system");
                }
                List<NcAttendSummary> ncAttendSummaries = ncAttendSummaryMapper.selectNcAttendSummaryList(ncAttendSummary);
                if(ncAttendSummaries.size()!=0){
                    ncWagesGzhsMapper.deleteNcWagesGzhsByNy(ny);
                    ncGsjsMapper.deleteNcGsjsByYn(ny);

                    for(NcWagesAccount account : ncWagesAccounts){
                        BeanUtils.copyProperties(account,ncWagesGzhs);
                        List<NcAttendSummary> collect = ncAttendSummaries.stream().filter(s -> s.getJobNo().equals(account.getJobNum())).collect(Collectors.toList());
                        if(collect.size()>0){
                            NcAttendSummary summary = collect.get(0);
                            ncWagesGzhs.setCurrentYm(ny);
                            ncWagesGzhs.setActualDayNum(summary.getActualDayNum());
                            ncWagesGzhs.setActualHour(summary.getActualDayNum().multiply(new BigDecimal(8)));
                            ncWagesGzhs.setRestDayNum(summary.getRestDay());
                            ncWagesGzhs.setLeaveDayNum(summary.getLeaveDay());
                            ncWagesGzhs.setDepartureChaDayNum(summary.getXlzqqDay());
                            ncWagesGzhs.setYcqDayNum(summary.getYcqDay());
                            ncWagesGzhs.setJjryqHours(summary.getJjrTime());
                            ncWagesGzhs.setWorkOvertime(summary.getJbTime());
                            ncWagesGzhs.setTbdxDayNum(summary.getTbdkDay());
                            ncWagesGzhs.setDxwTime(summary.getSytbHours());
                            ncWagesGzhs.setAttendCalBase(new BigDecimal(summary.getAttendCalBase()));
                            if(StringUtils.isNull(summary.getJbTime())){
                                ncWagesGzhs.setJbType(0D);
                            }else{
                                ncWagesGzhs.setJbType(summary.getJbTime().doubleValue());
                            }
                        }
                        if(StringUtils.isNull(ncWagesGzhs.getBaseWages())){
                            ncWagesGzhs.setBaseWages(BigDecimal.valueOf(0));
                        }
                        ncWagesGzhs.setWagesTotal(HrGeneraRuleUtils.gzhj(ncWagesGzhs.getBaseWages(),ncWagesGzhs.getZrgwWages(),ncWagesGzhs.getJxWages()));
                        ncWagesGzhs.setYfBasicWages(HrGeneraRuleUtils.yfjbgz(ncWagesGzhs.getJbType(),ncWagesGzhs.getAttendCalBase(),ncWagesGzhs.getBaseWages()));
                        ncWagesGzhs.setYfGwzrWages(HrGeneraRuleUtils.yfgwgz(ncWagesGzhs.getJbType(),ncWagesGzhs.getZrgwWages(),ncWagesGzhs.getAttendCalBase()));
                        ncWagesGzhs.setYfJbWages(HrGeneraRuleUtils.workOverTime(ncWagesGzhs.getJbType(),ncWagesGzhs.getDxwTime(),ncWagesGzhs.getBaseWages(),ncWagesGzhs.getZrgwWages(),ncWagesGzhs.getAttendCalBase()));
                        ncWagesGzhs.setYfJxWages(HrGeneraRuleUtils.yfjxgz(ncWagesGzhs.getJbType(),ncWagesGzhs.getJxWages(),ncWagesGzhs.getAttendCalBase()));
                        if("小时".equals(account.getJcWay())){
                            ncWagesGzhs.setHourMgz(HrGeneraRuleUtils.ydgz(ncWagesGzhs.getActualHour(),ncWagesGzhs.getHourMoney()));
                        }else{
                            ncWagesGzhs.setHourMgz(BigDecimal.valueOf(0));
                        }
                        NcPieceworkMoneySummary moneySummary = new NcPieceworkMoneySummary();
                        moneySummary.setJobNo(account.getJobNum());
                        moneySummary.setPieceworkDate(ny);
                        List<NcPieceworkMoneySummary> ncPieceworkMoneySummaries = ncPieceworkMoneySummaryMapper.selectNcPieceworkMoneySummaryList(moneySummary);
                        if(ncPieceworkMoneySummaries.size()>0){
                            BigDecimal a = ncPieceworkMoneySummaries.get(0).getPieceworkSummary()==null?new BigDecimal(0) :ncPieceworkMoneySummaries.get(0).getPieceworkSummary();
                            ncWagesGzhs.setYfJjWages(a);
                        }else{
                            ncWagesGzhs.setYfJjWages(new BigDecimal(0));
                        }
                        ncWagesGzhs.setYfWagesTotal(yfgzhj(ncWagesGzhs));//应发工资合计
                        ncWagesGzhs.setGrsds(new BigDecimal(0));//个人所得税
                        ncWagesGzhs.setOtherKk(new BigDecimal(0));//其他扣款
                        ncWagesGzhs.setActualWagesTotal(actualWagesTotal(ncWagesGzhs));//实际发工资
                        BigDecimal sjse = calculateGs(ncWagesGzhs);
                        ncWagesGzhs.setDataSource("1");
                        ncWagesGzhs.setGrsds(sjse);
                        ncWagesGzhs.setActualWagesTotal(ncWagesGzhs.getActualWagesTotal().subtract(ncWagesGzhs.getGrsds()));
                        insertNcWagesGzhs(ncWagesGzhs);
                    }
                }
            }
        }
        return 1;
    }

    public BigDecimal yfgzhj(NcWagesGzhs ncWagesGzhs){


        double yfBasegz = ncWagesGzhs.getYfBasicWages()==null? 0:ncWagesGzhs.getYfBasicWages().doubleValue();
        double yfgwgz = ncWagesGzhs.getYfGwzrWages()==null?0:ncWagesGzhs.getYfGwzrWages().doubleValue();
        double yfjbgz = ncWagesGzhs.getYfJbWages()==null?0:ncWagesGzhs.getYfJbWages().doubleValue();
        double yfjxgz = ncWagesGzhs.getYfJxWages()==null?0:ncWagesGzhs.getYfJxWages().doubleValue();
        double yfjjgz = ncWagesGzhs.getYfJjWages()==null?0:ncWagesGzhs.getYfJjWages().doubleValue();
        double hourMgz = ncWagesGzhs.getHourMgz()==null?0:ncWagesGzhs.getHourMgz().doubleValue();//月度工资
        double yfjtgz = 0;
        if(ncWagesGzhs.getYfJtWages()!=null){
            yfjtgz = ncWagesGzhs.getYfJtWages().doubleValue();
        }
        double yftxgz = 0;
        if(ncWagesGzhs.getYfTxWages()!=null){
            yftxgz = ncWagesGzhs.getYfTxWages().doubleValue();
        }
        double qqj = 0;
        if(ncWagesGzhs.getQqj()!=null){
            qqj = ncWagesGzhs.getQqj().doubleValue();
        }
        double xlbt = 0;
        if(ncWagesGzhs.getXlbt()!=null){
            xlbt = ncWagesGzhs.getXlbt().doubleValue();
        }
        double xjjl = 0;
        if(ncWagesGzhs.getXjjl()!=null){
            xjjl = ncWagesGzhs.getXjjl().doubleValue();
        }

        double otherBt = 0;
        if(ncWagesGzhs.getOtherBt()!=null){
            otherBt = ncWagesGzhs.getOtherBt().doubleValue();
        }
        double gwbt = 0;
        if(ncWagesGzhs.getGwbt()!=null){
            gwbt = ncWagesGzhs.getGwbt().doubleValue();
        }

        double specialBt = 0;
        if(ncWagesGzhs.getSpecialBt()!=null){
            specialBt = ncWagesGzhs.getSpecialBt().doubleValue();
        }
        double cb = 0;
        if(ncWagesGzhs.getCb()!=null){
            cb = ncWagesGzhs.getCb().doubleValue();
        }
//        double gzf = ncWagesGzhs.getGzf().doubleValue();
        double yfWagesTotal = yfBasegz+yfgwgz+yfjbgz+yfjxgz+yfjjgz+yfjtgz+yftxgz+qqj+xlbt+xjjl+otherBt+gwbt+specialBt+cb+hourMgz;
        return new BigDecimal(yfWagesTotal);
    }

    public BigDecimal actualWagesTotal(NcWagesGzhs ncWagesGzhs){
        double yfWagesTotal = ncWagesGzhs.getYfWagesTotal().doubleValue();
        double insurance = 0;
        if(ncWagesGzhs.getInsurance()!=null){
            insurance = ncWagesGzhs.getInsurance().doubleValue();
        }

        double zfgjj = 0;
        if(ncWagesGzhs.getZfgjj()!=null){
            zfgjj = ncWagesGzhs.getZfgjj().doubleValue();
        }

        double grsds = 0;
        if(ncWagesGzhs.getGrsds()!=null){
            grsds = ncWagesGzhs.getGrsds().doubleValue();
        }
        double gzfkk = 0;
        if(ncWagesGzhs.getGzfkk()!=null){
            gzfkk = ncWagesGzhs.getGzfkk().doubleValue();
        }

        double otherKk = 0;
        if(ncWagesGzhs.getOtherKk()!=null){
            otherKk = ncWagesGzhs.getOtherKk().doubleValue();
        }

        double khfmj = 0;
        if(ncWagesGzhs.getKhfmj()!=null){
            khfmj = ncWagesGzhs.getKhfmj().doubleValue();
        }

        double reward = 0;
        if(ncWagesGzhs.getReward()!=null){
            reward = ncWagesGzhs.getReward().doubleValue();
        }
        double ac = yfWagesTotal - insurance - zfgjj - grsds - gzfkk - otherKk - khfmj - reward;
        return new BigDecimal(ac);
    }

    /*计算个税*/
    public BigDecimal calculateGs(NcWagesGzhs ncWagesGzhs){

        NcGsjs ncGsjs = new NcGsjs();
        ncGsjs.setNy(ncWagesGzhs.getCurrentYm());
        ncGsjs.setEmployeeName(ncWagesGzhs.getWaName());
        ncGsjs.setJobNo(ncWagesGzhs.getJobNum());
        ncGsjs.setYfgz(ncWagesGzhs.getYfWagesTotal());
        ncGsjs.setSbgjj(ncWagesGzhs.getInsurance().add(ncWagesGzhs.getZfgjj()));
        Calendar date = Calendar.getInstance();
        String year = String.valueOf(date.get(Calendar.YEAR));
        NcWagesGzhs gzhs = ncWagesGzhsMapper.selectLjgzTotal(ncWagesGzhs.getJobNum(), year);
        if(StringUtils.isNull(gzhs)){
            ncGsjs.setLjgz(new BigDecimal(0).add(ncGsjs.getYfgz()));
            ncGsjs.setLjsb(new BigDecimal(0).add(ncGsjs.getSbgjj()));
        }else{
            ncGsjs.setLjgz(gzhs.getActualWagesTotal().add(ncGsjs.getYfgz()));
            ncGsjs.setLjsb(gzhs.getInsurance().add(ncGsjs.getSbgjj()));
        }
        NcWagesGzhs gz = ncWagesGzhsMapper.selectLjCount(ncWagesGzhs.getJobNum(), year);
        if(StringUtils.isNull(gz)){
            ncGsjs.setLjkcs(new BigDecimal(5000));
        }else{
            ncGsjs.setLjkcs(new BigDecimal((gz.getLjCount()+1)*5000));
        }
        NcGsjs ncGsjs1 = ncGsjsMapper.selectSjseCount(ncWagesGzhs.getJobNum());
        ncGsjs.setYjse(ncGsjs1.getYjse());

        NcGssz ncGssz = new NcGssz();
        ncGssz.setJobNo(ncWagesGzhs.getJobNum());
        List<NcGssz> ncGsszs = ncGsszMapper.selectNcGsszList(ncGssz);
        ncGsjs.setZnjy(ncGsszs.get(0).getZnjy());
        ncGsjs.setSylr(ncGsszs.get(0).getSylr());
        ncGsjs.setZfdklx(ncGsszs.get(0).getZfdklx());
        ncGsjs.setZfzj(ncGsszs.get(0).getZfzj());
        ncGsjs.setJxjy(ncGsszs.get(0).getJxjy());
        ncGsjs.setCreateTime(new Date());
        ncGsjs.setCreateBy(SecurityUtils.getUsername());
        ncGsjs.setYnssde(HrGeneraRuleUtils.ynssde(ncGsjs.getLjgz(),ncGsjs.getLjkcs(),ncGsjs.getLjsb(),ncGsjs.getZnjy(),ncGsjs.getSylr(),ncGsjs.getZfdklx(),ncGsjs.getZfzj(),ncGsjs.getJxjy()));
        ncGsjs.setRate(HrGeneraRuleUtils.slAndykl(ncGsjs.getYnssde()));
        ncGsjs.setSskcs(HrGeneraRuleUtils.sskcs(ncGsjs.getRate().doubleValue()));
        ncGsjs.setYnse(HrGeneraRuleUtils.ynse(ncGsjs.getYnssde(),ncGsjs.getRate().doubleValue(),ncGsjs.getSskcs()));
        ncGsjs.setSjse(ncGsjs.getYnse());
        ncGsjs.setBalance(HrGeneraRuleUtils.balance(ncGsjs.getYnse(),ncGsjs.getYjse()));

        ncGsjs.setUpdateTime(DateUtils.getNowDate());
        ncGsjs.setUpdateBy(SecurityUtils.getUsername());

        ncGsjsMapper.insertNcGsjs(ncGsjs);

        return ncGsjs.getSjse();
    }



}
